// src/services/post.js 或 post.ts

import { http,baseURL } from '@/utils/http'  // 根据你的项目结构调整路径

// 获取所有帖子列表
export const getAllPosts = () => {
  return http({
    method: 'GET',
    url: '/post',
  })
}
//分页查询帖子
export const findPaginated=(page,pageSize)=>{
  return http({
    method:'GET',
    url:`/post/list/${page}/${pageSize}`
  })
}

export const uploadPostWithFile=({
  filePath,
  scenicSpotId = 1,
  address,
  addressDescription,
  idea,
  shotTime,
  environment,
  token
})=>{
 return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: baseURL+'/post',
      filePath,
      name: 'file',
      formData: {
        scenicSpotId,
        address,
        addressDescription,
        idea,
        shotTime,
        environment,
      },
      header: {
        Authorization: token,
      },
      success: (res) => {
        if (res.statusCode === 200 || res.statusCode === 201) {
          resolve(res)
        } else {
          reject(new Error('上传失败，状态码：' + res.statusCode))
        }
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

export const getAllCities=()=>{
  return http({
    method:'GET',
    url:'/city'
  })
}
export const getSpotsByCity=(cityId)=>{
  return http({
    method:'GET',
    url:`/scenic-spot/city/${cityId}`
  })
}